//
//  WD_LittleGirlView.m
//  BUDING
//
//  Created by HanWoonYong on 16/4/12.
//  Copyright © 2016年 HanWoonYong. All rights reserved.
//

#import "WD_LittleGirlView.h"

@interface WD_LittleGirlView()
@property (nonatomic, strong)UIImageView *picture;
@property (nonatomic, assign)CGPoint point;
@end

@implementation WD_LittleGirlView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
//        self.backgroundColor = [UIColor redColor];
        self.picture = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
        self.picture.image = [UIImage imageNamed:@"1"];
        NSMutableArray *imageArr = [NSMutableArray arrayWithCapacity:0];
        for (int i = 1; i < 6; i++) {
            NSString *imageName = [NSString stringWithFormat:@"%d.png", i];
            UIImage *image = [UIImage imageNamed:imageName];
            [imageArr addObject:image];
        }
        [self.picture setAnimationImages:imageArr];
        [self.picture setAnimationRepeatCount:10000];
        [self.picture setAnimationDuration:0.7];
        [self.picture startAnimating];
        [self addSubview:self.picture];
    }
    return self;
}

// 点击开始
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    self.point = [touch locationInView:self];
}

// 点击移动
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    if (!self.state) {
        return;
    }
    UITouch *touch = [touches anyObject];
    CGPoint newPoint = [touch locationInView:self];
    float consetX = newPoint.x - self.point.x;
    float consetY = newPoint.y - self.point.y;
    self.center = CGPointMake(consetX + self.center.x, consetY+self.center.y);
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
